const mongoose = require("mongoose");

const Ques = require("../models/examination");

let options = {
  useNewUrlParser: true,
  useFindAndModify: false,
  useCreateIndex: true,
  autoIndex: false
};

mongoose.connect("mongodb://book:ABABcdcd1212@106.12.140.35/book", options);
mongoose.connection
  .on("open", () => {
    console.log("MongoDB Connected!");
  })
  .on("error", console.error);

const models = require("../answer.js");
const question = models.questions;

question.map(async function(item) {
  console.log(item.id);
  const q1 = await Ques.find({ id: item.id }, async function(err, res) {
    if (err) {
      console.error(err);
    }
    res["0"].options.map(ite => {
      item.options.map(it => {
        if (ite.id === it.id) {
          ite.isRight = true;
          res["0"].answered = true;
        }
      });
    });
    console.log(res["0"]);
    const rr = await Ques.findOneAndUpdate({ id: item.id }, res["0"], {
      new: true
    });
  });
});
